package cn.edu.thu.log.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class ParameterConstructor {
    private static Map<String, ArrayList<String>> productlistMap;

    static {
        productlistMap = new HashMap<String, ArrayList<String>>();
        ArrayList musicArray = new ArrayList<String>();
        musicArray.add("musicjump");
        musicArray.add("musicsearch");
        musicArray.add("musicclick");
        //   musicArray.add("musictrans");
        productlistMap.put("music", musicArray);

        ArrayList pageArray = new ArrayList<String>();
        pageArray.add("pageclick");
        pageArray.add("pagesearch");
        pageArray.add("pagesnapshot");
        productlistMap.put("page", pageArray);
        ArrayList newsarray = new ArrayList<String>();
        newsarray.add("newsclick");
        newsarray.add("newssearch");
        // newsarray.add("newssub");
        productlistMap.put("news", newsarray);
        ArrayList imagearray = new ArrayList<String>();
        imagearray.add("imageclick");
        imagearray.add("imagesearch");
        productlistMap.put("image", imagearray);
        ArrayList transarray = new ArrayList<String>();
        transarray.add("webtrans");
        transarray.add("imagetrans");
        transarray.add("musictrans");
        productlistMap.put("transservice", transarray);
        ArrayList accarray = new ArrayList<String>();
        accarray.add("accbind");
        accarray.add("accbindweibo");
        //  accarray.add("accesslog");
        accarray.add("accfindpwd");
        accarray.add("acchistoryop");
        accarray.add("acclogin");
        accarray.add("accreg");
        accarray.add("accverify");
        accarray.add("mypangupage");
        accarray.add("favLog");
        productlistMap.put("mypangu", accarray);
        ArrayList InfoSend = new ArrayList<String>();
        InfoSend.add("smssend");
        InfoSend.add("msgtrace");
        productlistMap.put("infosend", InfoSend);
        ArrayList navarray = new ArrayList<String>();
        navarray.add("navclick");
        //navarray.add("navonload");
        productlistMap.put("navigation", navarray);
        ArrayList clientarray = new ArrayList<String>();
        // clientarray.add("clientactive");
        clientarray.add("clientdownload");
        productlistMap.put("clientdownload", clientarray);
        ArrayList otherarray = new ArrayList<String>();
        otherarray.add("otherclick");
        otherarray.add("otherpage");
        productlistMap.put("other", otherarray);
        ArrayList realarray = new ArrayList<String>();

        realarray.add("realclick");
        realarray.add("realsearch");
        productlistMap.put("real", realarray);



    }

    ;
	
	public String InputPathConstructor(String startingDate,String endingDate,String productlist ){
        String inputpaths = "";
     String baseinputpath = "/warehouse/";
     String[] products = productlist.split("/");
     DateFormat df = new SimpleDateFormat("yyyyMMddHH");
     DateFormat df2 =  new SimpleDateFormat("yyyy/MM/dd");
     for (int i = 0; i < products.length; i++) {
         ArrayList<String> pl = productlistMap.get(products[i]);
         if(pl == null )
             continue;
         for (int j = 0; j < pl.size(); j++) {
        	 Date d1 = null; 
        			      
             //d1.setHours(Integer.valueOf(this.startinghour));        	 
             Date d2 = null ; 
            	
             try{
            	 d1 =  df2.parse(startingDate);      
            	 d2 =  df2.parse(endingDate);
             } catch(Exception e){
            	 
             }
             //d2.setHours(Integer.valueOf(this.finishinghour));
             for (; d1.getTime() <= d2.getTime(); d1.setHours(d1.getHours()+1)) {
                 String temppath = df.format(d1);
               //  System.out.println(temppath);
                 //     System.out.println("i:"+i);
                 String inputtemppath = "";
                 inputtemppath = baseinputpath + pl.get(j) + "/"+"duration=" + temppath+"/"+pl.get(j)+"_"+temppath;
                 if(!FilePathChecker.isExist(inputtemppath))
                 {                
                	 continue;
                 }
                 if (inputpaths.equals("") ) {
                     inputpaths += inputtemppath;
                 } else {
                     inputpaths += "," +inputtemppath;
                 }

             }
         }

     }
     return inputpaths;
		
	}
	public static void main(String [] args){
		ParameterConstructor pc = new ParameterConstructor();
		System.out.println(pc.InputPathConstructor("2012/06/01", "2012/06/02", "other"));
		
	}

}
